package com.hdit.guimei.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 李嘉明
 * @基本功能: 拦截未登录的用户
 * @ClassNameLoginValidateInterceptor
 * @Description TODO
 * @Date 2021/1/16 16:05
 * @Version 1.0
 */
public class AdminLoginValidateInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session =request.getSession();
        if(session.getAttribute("admin_name")==null) {
            response.getWriter().write("您还没登录，请先登录！");
            return false;
        }
        return true;
    }
    @Override
    public void afterCompletion(HttpServletRequest req, HttpServletResponse resp, Object arg2, Exception arg3)
            throws Exception {
        //执行完毕，返回前拦截
    }

    @Override
    public void postHandle(HttpServletRequest req, HttpServletResponse resp, Object arg2, ModelAndView arg3)
            throws Exception {
        //处理过程中执行拦截
    }

}
